package com.chen.nongansampling.presenter;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.chen.nongansampling.R;
import com.chen.nongansampling.bean.LoginRequest;
import com.chen.nongansampling.bean.qrcode.FormatBySamplingBean;
import com.chen.nongansampling.bean.qrcode.QRcodeCallback;
import com.chen.nongansampling.bean.qrcode.QRcodeRequest;
import com.chen.nongansampling.manager.DataManager;
import com.chen.nongansampling.model.Account;
import com.chen.nongansampling.model.CallbackData;
import com.chen.nongansampling.presenterView.LabelPrintedView;
import com.chen.nongansampling.presenterView.RiskMonitorView;

import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

public class LabelPrintedPresenter extends BasePresenter {
    private Context mContext;
    private LabelPrintedView labelPrintedView;
    public QRcodeCallback data;
   public  FormatBySamplingBean  formatBySamplingBeanCallbackData;


    @Override
    public void BindPresentView(Object presentView) {
        labelPrintedView=(LabelPrintedView) presentView;
    }
    public LabelPrintedPresenter(Context context){
        this.mContext = context;
    }


    public void getUrlBySamplingPkId(QRcodeRequest qRcodeRequest) {



        DataManager.getInstance(mContext).getUrlBySamplingPkId(qRcodeRequest)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<QRcodeCallback>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(QRcodeCallback qRcodeCallback) {
                        data=qRcodeCallback;

                    }

//                    @Override
//                    public void onNext(QRcodeCallback qRcodeCallback) {
//                        this.qRcodeCallback    =  qRcodeCallback;
//
//                    }




                    @Override
                    public void onError(Throwable e) {


                        labelPrintedView.onError(e.toString());
                    }

                    @Override
                    public void onComplete() {


                        if (data != null) {

                            labelPrintedView.onSuccess(data);
                        }
             //           LabelPrintedPresenter.super.compositeDisposable.dispose();
                    }
                });
    }


    public void getFormatBySamplingPkIdReseponseInfo(QRcodeRequest qRcodeRequest) {
        DataManager.getInstance(mContext).getFormatBySamplingPkIdReseponseInfo(qRcodeRequest)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Observer<FormatBySamplingBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(FormatBySamplingBean data) {
                        formatBySamplingBeanCallbackData=data;

                    }




                    @Override
                    public void onError(Throwable e) {

                        labelPrintedView.onError(e.toString());
                    }

                    @Override
                    public void onComplete() {

                        if (formatBySamplingBeanCallbackData != null) {


                            labelPrintedView.getFormatBySamplingPkIdReseponseInfo(formatBySamplingBeanCallbackData);

                        }
                        //           LabelPrintedPresenter.super.compositeDisposable.dispose();
                    }
                });
    }



}
